import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BatteryIndicator extends StatelessWidget {
  final int batteryLevel; // 电池电量，范围 0 到 100
  final bool canCast;
  const BatteryIndicator({
    Key? key,
    required this.batteryLevel,
    required this.canCast,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Container(
          width: 21.w, // 控件宽度
          height: 12.h, // 控件高度
          child: Stack(
            children: [
              // 电池电量
              Positioned(
                left: 2.w,
                top: 0,
                bottom: 0,
                child: Align(
                  // 使用 Align 小部件
                  alignment: Alignment.center, // 垂直居中
                  child: SizedBox(
                    width: 16.w * batteryLevel / 100,
                    height: 7.55.h,
                    child: Container(
                      color: canCast
                          ? (batteryLevel > 20 ? Colors.green : Colors.red)
                          : Colors.grey,
                    ),
                  ),
                ),
              ),
              // 电池图标
              Image.asset(
                canCast
                    ? (batteryLevel > 20
                        ? 'assets/images/Vector@2x (4).png'
                        : 'assets/images/Vector@2x (5).png')
                    : 'assets/images/Vector@2x (6).png',
                width: 21.w,
                height: 12.h,
              ),
            ],
          ),
        ),
        5.horizontalSpace,
        Text(
          '$batteryLevel%',
          style: TextStyle(
            fontSize: 14.sp,
            fontWeight: FontWeight.w400,
            color: canCast ? const Color.fromRGBO(102, 102, 102, 1) : const Color.fromRGBO(153, 153, 153, 1),
          ),
        ),
      ],
    );
  }
}
